package com.lfy.chat.service;

import cn.hutool.json.JSONUtil;
import com.lfy.chat.domain.ws.resp.BaseResp;
import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * chatServiceUtil
 *
 * @author <a href="https://www.lvfeiy.top">吕飞扬</a>
 * @date 2023/10/25 0:25
 */
public abstract class BaseChatService {
    public static void sendMsg(Channel channel, BaseResp<?> baseResp ){
        String json = JSONUtil.toJsonStr(baseResp);
        channel.writeAndFlush(new TextWebSocketFrame(json));
    }
    public static String formatDateWithChinese(Date date){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm:ss");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
        String hourMS = simpleDateFormat.format(date);
        String yearMD = dateFormat.format(date);
        String fG = "12:00:00";
        String result;
        if(hourMS.compareTo(fG) >0){
            result = yearMD.concat(" 下午").concat(hourMS);
        }else {
            result = yearMD.concat(" 上午").concat(hourMS);
        }
        return result;

    }
    public static String formatDate(Date date){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return simpleDateFormat.format(date);
    }

    public static void main(String[] args) {
        Date date = new Date();
        String s = formatDate(date);
        System.out.println(s);


    }
}
